

from django.shortcuts import render
from django.views.generic import View
from contents.models import ContentCategory
from pprint import pprint
from PMSP.utils.my_category import get_category

# 1,首页类视图
class IndexView(View):
    def get(self,request):

        # 1，获取分类
        categories = get_category()

        # 2,查询广告数据
        contents = {}
        content_category = ContentCategory.objects.order_by("id")
        for category in content_category:
            contents[category.key] = category.contents.all()

        # 3，返回分类和首页内容，渲染页面
        return render(request,template_name='index.html',context={"categories":categories,"contents":contents})

